package com.yingu.bookmanage_ssm1.Services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yingu.bookmanage_ssm1.Dao.BookDao;
import com.yingu.bookmanage_ssm1.Pojo.BookPojo;

@Service
public class BookServiceImpl implements BookService{
	@Autowired
	BookDao bookDao;

	@Override
	public List<BookPojo> findAll(int x, int pageSize) {
		int indexPage=(x-1)*pageSize;
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("indexPage",indexPage);
		map.put("pageSize",pageSize);
		
		return bookDao.findAll(map);
	}

	@Override
	public int count() {
		
		return bookDao.count();
	}

	@Override
	public int countPage(int pageSize) {
		int count = bookDao.count();
		if(count%pageSize==0){
			return count/pageSize;
		}else{
			return count/pageSize+1;
		}
	}

	
	
	@Override
	public boolean delete(int id) {
		int flag = bookDao.delete(id);
		if(flag>0){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean addBook(BookPojo bp) {
		int flag = bookDao.addBook(bp);
		if(flag>0){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean updateBook(BookPojo bp) {
		int flag = bookDao.updateBooke(bp);
		if(flag>0){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public BookPojo findById(int id) {
		
		return bookDao.findById(id);
	}

}
